package _01_动态数组;

public class _223_矩形面积 {

    public static void main(String[] args) {
        _223_矩形面积 v = new _223_矩形面积();
        System.out.println(v.computeArea(-2, -2, 2, 2, -4, 3, -3, 4));
    }

    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        // 首先计算两个矩形的总面积
        int rangle1Area = (ax2 - ax1) * (ay2 - ay1);
        int rangle2Area = (bx2 - bx1) * (by2 - by1);
        // 如果两个矩形不相交
        int coverArea = 0;
        if (bx1 < ax2 && ax1 < bx2 && by1 < ay2 && ay1 < by2) {
            // 计算覆盖面积
            coverArea = (Math.min(bx2, ax2) - Math.max(bx1, ax1)) * (Math.min(by2, ay2) - Math.max(by1, ay1));
        }
        return rangle1Area + rangle2Area - coverArea;
    }

}
